<?php include("verification.php");?>

<?php
	$players = Array();
	$matchs = mysql_query('SELECT * FROM tournamentMatch, tournamentDraw, ' .
		'tournamentDrawType WHERE tournamentMatch.idTournamentDraw = tournamentDraw.idTournamentDraw' .
		' AND tournamentDraw.idTournamentDrawType = 1 GROUP BY idTournamentMatch');
	
	while ($participation = mysql_fetch_array($matchs)) {
	  for ($i = 1; $i <= 4; $i++) {
	    $idPlayer = 'idPlayer' . $i;
	    if ($participation[$idPlayer] != 0) {
	      $players[$participation[$idPlayer]]['idPlayer'] = $participation[$idPlayer];
	      $players[$participation[$idPlayer]]['nbMatchs'] = ($players[$participation[$idPlayer]]['nbMatchs'] == NULL) ?
	          1 : $players[$participation[$idPlayer]]['nbMatchs'] + 1;
	          
	      $players[$participation[$idPlayer]]['gameWonCount']
	      	  = getGameWonCount($participation[$idPlayer]);
	          
	    }
	  }
	}


?>



<?php
	function sortByNbGameWonCount ($val1, $val2) {
		return $val1['gameWonCount'] < $val2['gameWonCount'];
	}
	
	usort($players, "sortByNbGameWonCount");
  	for ($i = 0; $i < count($players); $i++) {
?>
      <td><?php echo getPlayerSurName($players[$i]['idPlayer']); ?></td>
      <td><?php echo getPlayerLastName($players[$i]['idPlayer']); ?></td>
      <td><?php echo $players[$i]['gameWonCount'] ?></td>
      
	  <br/>
<?php
	}


?>




